package com.android.lovely.data

import com.android.lovely.room.role.CreateRole
import com.android.lovely.room.role.NewCard
import com.android.lovely.room.role.NewPrice
import com.squareup.moshi.Json
import com.squareup.moshi.JsonClass
import java.text.SimpleDateFormat
import java.util.Locale

@JsonClass(generateAdapter = true)
data class CardWrapper(
    @Json(name = "max_card_num") val maxCardNum: Int? = 0,
    @Json(name = "list") val list: List<NewPrice>? = emptyList()
)


@JsonClass(generateAdapter = true)
data class SmartRole(
    @Json(name = "name") val name: String = "",
    @Json(name = "gender") val gender: Int = 0,
    @Json(name = "personality") val personality: String = "",
    @Json(name = "scenario") val scenario: String = "",
    @Json(name = "first_msg") val firstMsg: String = "",
    @Json(name = "example_chat") val exampleChat: String = "",
    @Json(name = "description") val description: String = "",
)

@JsonClass(generateAdapter = true)
data class CreateRoleRequest(
    @Json(name = "id") var id: Int? = null,
    @Json(name = "name") val name: String,
    @Json(name = "introduction") val introduction: String,
    @Json(name = "description") val description: String,
    @Json(name = "nsfw") val nsfw: Int,//0=审核模式或 a 面  1=非审核 b 面
    @Json(name = "first_message") val firstMessage: String,
    @Json(name = "avatar") val avatar: String,
    @Json(name = "gender") val gender: Int,//1=男性 2=女性 0=未知
    @Json(name = "privacy") val privacy: Int,//1=公开 2=仅自己可见
    @Json(name = "chat_example") val chatExample: String,
    @Json(name = "scenario") val scenario: String,
    @Json(name = "category") val category: Int,
    @Json(name = "search_tag") val searchTag: String,
    @Json(name = "card_list") val cardList: List<NewCard>,
)

@JsonClass(generateAdapter = true)
data class RemoteCardPackage(
    @Json(name = "card_list") val cardList: List<RemoteCardItem> = listOf(),
)

@JsonClass(generateAdapter = true)
data class RemoteCardItem(
    @Json(name = "id") val id: Int = 0,
    @Json(name = "img_detail") val imgDetail: String = "",
    @Json(name = "img_url") val imgUrl: String = ""
)

@JsonClass(generateAdapter = true)
data class RoleHistory(
    @Json(name = "avatar") val avatar: String = "",
    @Json(name = "card_num") val cardNum: Int = 0,
    @Json(name = "collect_num") val collectNum: Int = 0,
    @Json(name = "bot_id") val botId: Int = 0,
    @Json(name = "bot_name") val botName: String = "",
    @Json(name = "c_time") val cTime: String = "",
    @Json(name = "category") val category: Int = 0,
    @Json(name = "chat_example") val chatExample: String = "",
    @Json(name = "description") val description: String = "",
    @Json(name = "first_message") val firstMessage: String = "",
    @Json(name = "gender") val gender: Int = 0,
    @Json(name = "id") val id: Int = 0,
    @Json(name = "name") val name: String = "",
    @Json(name = "personality") val personality: String = "",
    @Json(name = "privacy") val privacy: Int = 0,
    @Json(name = "reject_msg") val rejectMsg: String = "",
    @Json(name = "scenario") val scenario: String = "",
    @Json(name = "status") val status: Int = 0, //1=待审核 2=审核通过 3=审核被拒绝
    @Json(name = "type") val type: Int = 0,
    @Json(name = "search_tag") val searchTag: String = "",
    @Json(name = "cover_image") val coverImage: Map<String, String> = emptyMap()
) {
    fun toCreateRole(): CreateRole {
        return CreateRole(
            id = id,
            createId = id,
            botId = botId,
            nickName = name,
            avatar = avatar,
            gender = gender,
            nsfw = type == 1,
            public = privacy == 1,
            category = category,
            introduction = personality,
            keywords = if (searchTag.isEmpty()) emptyList() else searchTag.split(","),
            description = description,
            scenario = scenario,
            firstMessage = firstMessage,
            chatExample = chatExample,
            status = status,
            statusReply = rejectMsg,
            createTime = runCatching {
                SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.getDefault()).parse(cTime)?.time
                    ?: System.currentTimeMillis()
            }.getOrDefault(System.currentTimeMillis())
        )
    }
}

@JsonClass(generateAdapter = true)
data class CreatorInfo(
    @Json(name = "role_list") val roleList: List<CreatorRole> = listOf(),
    @Json(name = "user_info") val userInfo: Creator = Creator()
)

@JsonClass(generateAdapter = true)
data class CreatorRole(
    @Json(name = "id") val id: Int = 0,
    @Json(name = "collect_num") val collectNum: Int = 0,
    @Json(name = "cover_image") val coverImage: Map<String, String> = emptyMap(),
    @Json(name = "personality") val personality: String = "",
    @Json(name = "type") val type: Int = 0,
    @Json(name = "gender") val gender: Int = 0,
    @Json(name = "search_tag") val searchTag: String = "",
    @Json(name = "name") val name: String = "",
    @Json(name = "card_num") val cardNum: Int = 0
)

@JsonClass(generateAdapter = true)
data class Creator(
    @Json(name = "head_img") val headImg: String = "",
    @Json(name = "name") val name: String = "",
    @Json(name = "bot_count") val botCount: Int = 0
)